<template>
  <el-card shadow="hover">
    <el-form inline>
      <el-form-item label="一级分类">
        <el-select
          v-model="useCategoryStore.category1Id"
          placeholder="请选择"
          @change="category1Handler"
          :disabled="scene != 0"
        >
          <el-option
            :label="category1.name"
            :value="category1.id"
            v-for="(category1, index) in useCategoryStore.category1List"
            :key="category1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          placeholder="请选择"
          @change="category2Handler"
          v-model="useCategoryStore.category2Id"
          :disabled="scene != 0"
        >
          <el-option
            :label="category2.name"
            :value="category2.id"
            v-for="(category2, index) in useCategoryStore.category2List"
            :key="category2.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          placeholder="请选择"
          v-model="useCategoryStore.category3Id"
          :disabled="scene != 0"
        >
          <el-option
            :label="category3.name"
            :value="category3.id"
            v-for="(category3, index) in useCategoryStore.category3List"
            :key="category3.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts" setup>
import { onMounted } from "vue";

import categoryStore from "@/stores/category"; // 引入store仓库

defineProps(["scene"]);
const useCategoryStore = categoryStore(); // store仓库对象

// 一级分类选中值发生变化时触发的回调
const category1Handler = () => {
  useCategoryStore.getCategory2List();
};

// 二级分类选中值发生变化时触发的回调
const category2Handler = () => {
  useCategoryStore.getCategory3List();
};

onMounted(() => {
  useCategoryStore.getCategory1List();
});
</script>

<style scoped></style>
